//
//  XMMeetBoxCell.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/5/27.
//

#import "XMMeetBoxCell.h"

@interface XMMeetBoxCell ()

@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) UIImageView *avatarImgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *stateLabel;

@end

@implementation XMMeetBoxCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.avatarImgView];
    [_avatarImgView addSubview:self.stateLabel];
    _stateLabel.hidden = YES;
    [self addSubview:self.nameLabel];
    [self addSubview:self.priceLabel];
    [self.contentView addSubview:self.selectBtn];
    
    [self addSubview:self.dateLabel];
    [self addSubview:self.stateLabel];
    UILabel *dateTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_priceLabel.x, _dateLabel.y, kScreenWidth/2 - _priceLabel.x, _dateLabel.height) font:KFontSize(12.0) textColor:kColorHEX(0x666666)];
    dateTitleLabel.text = @"见面时间";
    [self addSubview:dateTitleLabel];
}

- (void)setContentWithBoxModel:(XMServiceVosModel *)boxModel select:(BOOL)selected {
//    _avatarImgView.image = [UIImage imageWithColor:kColorHEX(0x00ffff)];
    [_avatarImgView sd_setImageWithURL:[NSURL URLWithString:boxModel.img]];
    _nameLabel.text = boxModel.title;//@"简介简介简介简介简介简介";
    _priceLabel.text = [NSString stringWithFormat:@"¥%@", boxModel.price];//@"1300.00"];
    _dateLabel.text = [[NSDate dateWithTimeIntervalSince1970:[boxModel.time integerValue]/1000] dateStringWithFormat:@"yyyy-MM-dd HH:mm"];///@"2025-05-27 03:33";
    _selectBtn.selected = selected;
}

- (void)selectAction:(UIButton *)button {
    button.selected = !button.selected;
    self.itemSelectBlock ? self.itemSelectBlock(button.selected) : nil;
}

#pragma mark - Init
- (UIButton *)selectBtn {
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom frame:CGRectMake(KScaleWidth(5.0), (KScaleWidth(105.0) - KScaleWidth(28.0))/2, KScaleWidth(28.0), KScaleWidth(28.0)) image:@"mine_select_icon" selectImg:@"mine_select_icon_select"];
        [_selectBtn addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

- (UIImageView *)avatarImgView {
    if (!_avatarImgView) {
        _avatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(35.0), KScaleWidth(16.0), KScaleWidth(79.0), KScaleWidth(79.0))];
        [_avatarImgView setCornerRadius:KScaleWidth(8.0)];
    }
    return _avatarImgView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.avatarImgView.maxX + KScaleWidth(15.0), KScaleWidth(15.0), kScreenWidth - _avatarImgView.maxX - KScaleWidth(15.0) - KScaleWidth(17.0), KScaleWidth(22.0)) font:KFontSize(16.0) textColor:kColorHEX(0x333333)];
    }
    return _nameLabel;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLabel.x, _nameLabel.maxY, _nameLabel.width, KScaleWidth(31.0)) font:KBoldFontSize(18.0) textColor:kColorHEX(0x333333)];
    }
    return _priceLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth/2, self.priceLabel.maxY + KScaleWidth(4.0), kScreenWidth/2 - KScaleWidth(17.0), KScaleWidth(27.0)) font:KFontSize(12.0) textColor:kColorHEX(0x666666) textAlignment:NSTextAlignmentRight];
    }
    return _dateLabel;
}

- (UILabel *)stateLabel {
    if (!_stateLabel) {
        _stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.avatarImgView.height - KScaleWidth(20.0), _avatarImgView.width, KScaleWidth(20.0)) font:KFontSize(14.0) textColor:kColorHEX(0xffffff) textAlignment:NSTextAlignmentCenter];
        _stateLabel.backgroundColor = kColorHEX(0xD9D9D9);
    }
    return _stateLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
